package cn.zymall.merchant.controller;

import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.Merchant;
import cn.zymall.common.utils.staticc.DiscernField;
import cn.zymall.merchant.service.MerchantAccountService;
import cn.zymall.merchant.service.impl.MerchantAccountServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName 店铺账号的crud
 * @Description TODO
 * @Author chenmei
 * @Date 2020/8/17 16:02
 * @Version 1.0
 **/
@RestController
@RequestMapping("/merchantAccount")
public class MerchantAccountController extends BaseController<MerchantAccountService, Merchant> {
	@Autowired
	MerchantAccountServiceImpl merchantAccountService;


	/**
	 *
	 * @return 返回所有店铺
	 */
    @GetMapping("/getAllMerchant")
	public List<Merchant> getAllMerchant(Integer merchantStatusId){
		List<Merchant> merchant=merchantAccountService.getAllMerchant(merchantStatusId);
		return merchant;
	}


	/**
	 * 获取单个店铺
	 * @param merchantId
	 * @return 单个店铺
	 */
	@GetMapping("/getSingelMerchant")
	public Merchant getSingelMerchant(Integer merchantId){

		return merchantAccountService.getSingelMerchant(merchantId);
	}

	/**
	 * 只修改店铺状态
	 * @param merchantStatusId 店铺状态id
	 * @return
	 */
	@PutMapping("/updataMerchantStatus")
	public Integer updataMerchantStatus(Integer merchantId,Integer merchantStatusId) {
		return merchantAccountService.updataMerchantStatus(merchantId,merchantStatusId);
	}

	/**
	 *
	 */

	/**
	 * 获取身份证、营业执照图片信息
	 * @Author: chenmei
	 * @param cardInfo
	 * @Date: 2020/8/17 17:42
	 * @return:
	 **/
	@PostMapping("/getCardInfo")
	public String reverseCardInfo(String type,String cardInfo){
		/*try{
			String reverseCardInfo= DiscernField.card(type,cardInfo);//身份证正面
			return reverseCardInfo;
			//String SiteCardInfo=DiscernField.card("idcard",merchant.getSiteCardImg());//反面
			//String licenseInfo= DiscernField.card("business_license",merchant.getLicenseImg());//营业执照
		}catch (IOException i){
			i.getMessage();
			return "获取信息报错";
		}*/
		return "";
	}
    @PutMapping("/updataMerchantInfo")
	public Integer updataMerchantInfo(@RequestBody Merchant merchant) {
	    System.out.println(merchant+"----------///////////////////");
	   Integer i= merchantAccountService.updataMerchantInfo(merchant);
	    System.out.println("审核修改---------"+i);
	  return i;
    }

	/**
	 * 申请入驻商家
	 * @param merchant 店铺实体类
	 * @return 大于0添加成功 ,返之失败   (添加店铺成功,则未待审核状态)
	 */
	@PostMapping("/addMerchant")
	public Integer addMerchant(@RequestBody Merchant merchant) {
		System.out.println(merchant+"----------------商家入驻");
		return merchantAccountService.addMerchant(merchant);
	}

}
